package script;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class ScriptSample {

    public static void main(String[] args) throws ScriptException, NoSuchMethodException {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine scriptEngine = manager.getEngineByName("JavaScript");
        String funStr = "function sum(a, b) {return a+b;}";
        scriptEngine.eval(funStr);
        Invocable invocable = (Invocable) scriptEngine;
        Object result = invocable.invokeFunction("sum", 100, 99);
        System.out.println(result);
    }

}
